﻿CREATE SCHEMA [core] AUTHORIZATION [dbo]
GO
/* Core Logging-Table */
CREATE TABLE core.Logging
(
	/* Primary Key */
	PK_Logging INT NOT NULL IDENTITY,
	/* Date of the logging */
	LogDate DATETIME NOT NULL,
	/* Type of logging: 0 = Verbose, 1 = Info, 2 = Warning, 3 = Error */
	LogType INT NOT NULL,
	/* Version of the client that wrote the error message */
	VersionNumber VARCHAR(25) NOT NULL,
	/* SessionID of the client that wrote the error message */
	SessionID VARCHAR(50),
	
	/* Default Columns */
	CreatedAt DATETIME NOT NULL,
	CreatedBy NVARCHAR(256) NOT NULL,
	CreatedFromSource NVARCHAR(256) NOT NULL,
	ModifiedAt DATETIME,
	ModifiedBy NVARCHAR(256),
	ModifiedFromSource NVARCHAR(256)
) ON [FG_CORE]
GO

ALTER TABLE core.Logging
	ADD CONSTRAINT PK_Logging
		PRIMARY KEY(PK_Logging) ON [FG_INDEXES]
GO

ALTER TABLE core.Logging
	ADD CONSTRAINT DEF_core_Logging_LogDate
		DEFAULT GETDATE() FOR LogDate
GO

ALTER TABLE core.Logging
	ADD CONSTRAINT CHECK_core_Logging_LogType
		CHECK(LogType BETWEEN 0 AND 3)
GO

ALTER TABLE core.Logging
	ADD CONSTRAINT DEF_core_Logging_CreatedAt
		DEFAULT GETDATE() FOR CreatedAt